import 'package:cook_dinner/pages/chat/chat_view/chat_view.dart';
import 'package:cook_dinner/widgets/input.dart';
import 'package:flutter/material.dart';
import 'package:cook_dinner/config/include.dart';
import 'package:flutter/services.dart';

class ChatPage extends StatefulWidget {
  const ChatPage({Key? key}) : super(key: key);

  @override
  State<ChatPage> createState() => _ChatPageState();
}

class _ChatPageState extends State<ChatPage> {
  TextEditingController _editingController = TextEditingController();

  List<Widget> _list = [];

  @override
  void initState() {
    _list.add(time('05-14 22：18'));
    _list.add(LeftChat(message: '你好，我看了您的菜谱，感觉很有兴趣，如果以后有什么问题，我可以来问您吗？'));
    _list.add(RightChat(message: '可以的呀！以后一起学习'));
    setState(() {});
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      behavior: HitTestBehavior.translucent,
      onTap: () {
        FocusScope.of(context).unfocus();
      },
      child: Scaffold(
        resizeToAvoidBottomInset: true,
        backgroundColor: Colors.white,
        appBar: PreferredSize(
          preferredSize: Size.fromHeight(50.rpx + HYSizeFit.statusHeight),
          child: Padding(
            padding: EdgeInsets.only(top: HYSizeFit.statusHeight),
            child: Container(
              decoration: BoxDecoration(
                color: Colors.white,
                boxShadow: [
                  BoxShadow(
                    offset: Offset(0, 2.rpx), // 垂直偏移4px，水平偏移0
                    blurRadius: 4.rpx, // 模糊半径20px
                    spreadRadius: 0, // 扩展半径0，保持阴影大小不变
                    color: const Color(0xFF000000).withOpacity(0.06), //
                    // 颜色设置为透明度较低的黑色
                  ),
                ],
              ),
              width: HYSizeFit.screenWidth,
              height: 50.rpx,
              padding: EdgeInsets.only(left: 32.rpx, right: 27.rpx),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Row(
                    children: [
                      InkWell(
                        onTap: () => Navigator.pop(context),
                        child: Image.asset(
                          'assets/images/back_left.png',
                          height: 28.rpx,
                        ),
                      ),
                      SizedBox(width: 21.rpx),
                      Text(
                        '爱吃的小徐同学',
                        style: TextStyle(
                          fontSize: 18.rpx,
                          color: const Color(0xff333333),
                        ),
                      ),
                    ],
                  ),
                  Row(
                    children: [
                      Image.asset('assets/images/phone.png'),
                      SizedBox(width: 10.rpx),
                      Image.asset('assets/images/point.png'),
                    ],
                  ),
                ],
              ),
            ),
          ),
        ),
        body: SingleChildScrollView(
          child: Column(
            children: [
              Container(
                width: HYSizeFit.screenWidth,
                height:
                    HYSizeFit.screenHeight - 122.rpx - HYSizeFit.statusHeight,
                color: Colors.white,
                padding:
                    EdgeInsets.only(left: 26.rpx, right: 20.rpx, top: 31.rpx),
                child: ListView(
                  children: _list,
                ),
              ),
              Container(
                width: HYSizeFit.screenWidth,
                height: 72.rpx,
                padding: EdgeInsets.only(left: 30.rpx, right: 26.rpx),
                decoration: BoxDecoration(
                  color: const Color(0xffF5F5F5),
                  borderRadius: BorderRadius.circular(6.rpx),
                ),
                child: Row(
                  children: [
                    Image.asset(
                      'assets/images/voice.png',
                      width: 29.rpx,
                      height: 29.rpx,
                    ),
                    Expanded(
                      child: Container(
                        width: double.infinity,
                        height: 37.rpx,
                        margin: EdgeInsets.only(left: 20.rpx, right: 15.rpx),
                        padding: EdgeInsets.symmetric(horizontal: 10.rpx),
                        alignment: Alignment.center,
                        decoration: BoxDecoration(
                          color: Colors.white,
                          borderRadius: BorderRadius.circular(10.rpx),
                        ),
                        child: textInput(
                          controller: _editingController,
                        ),
                      ),
                    ),
                    Image.asset(
                      'assets/images/emote.png',
                      width: 29.rpx,
                      height: 29.rpx,
                    ),
                    SizedBox(width: 12.rpx),
                    InkWell(
                      onTap: () {
                        setState(() {
                          _list.add(
                            RightChat(
                              message: _editingController.text.toString(),
                            ),
                          );
                        });
                      },
                      child: Image.asset(
                        'assets/images/append.png',
                        width: 20.rpx,
                        height: 20.rpx,
                      ),
                    ),
                  ],
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
